package com.example.livereplay.common.controller;

import com.example.livereplay.common.model.enity.Comment;
import com.example.livereplay.common.model.request.InsertCommentRequest;
import com.example.livereplay.common.service.CommentService;
import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.common.web.ResultBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/comment")
@Tag(name = "评论管理")
public class CommentController {
    @Resource
    private CommentService commentService;

    @Operation(summary = "传入弹幕")
    @PostMapping("/insertComment")
    public ResultBean<Boolean> insertComment(@RequestBody @Valid InsertCommentRequest insertCommentRequest){
        return ResultBean.restResult(commentService.insert(insertCommentRequest), ErrorCodeInfo.OK);
    }

    @Operation(summary = "输出弹幕")
    @PostMapping("/showComment")
    public ResultBean<List<Comment>> show(@RequestBody @Valid String id){
        return ResultBean.restResult(commentService.findByVideoId(id), ErrorCodeInfo.OK);
    }
}
